package tms.service;

import java.util.List;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.Response;

import tms.model.Account;
import tms.model.Aircraft;
import tms.model.Booking;
import tms.model.Destination;
import tms.model.Flight;

@Path("/TravelService")
public class TravelService {
	
	@POST
	@Path("/destination/list")
	public Response getListDestination(String where){
		List<Destination> list = Destination.getListDynamic(where);
		GenericEntity<List<Destination>> res = new GenericEntity<List<Destination>>(list){};
		return Response.ok(res).build();
	}
	
	@POST
	@Path("/destination/first")
	public Response getFirstDestination(String where){
		Destination obj = Destination.getFirstDynamic(where);
		return Response.ok(obj).build();
	}
	
	@POST
	@Path("/destination/save")
	public Response updateDestination(Destination obj){
		return Response.ok(Destination.save(obj)).build();
	}
	
	@POST
	@Path("/destination/delete")
	public Response deleteDestination(Destination obj){
		return Response.ok(Destination.delete(obj)).build();
	}
	
	
	
	@POST
	@Path("/account/list")
	public Response getListAccount(String where){
		List<Account> list = Account.getListDynamic(where);
		GenericEntity<List<Account>> res = new GenericEntity<List<Account>>(list){};
		return Response.ok(res).build();
	}
	
	@POST
	@Path("/account/first")
	public Response getFirstAccount(String where){
		Account obj = Account.getFirstDynamic(where);
		return Response.ok(obj).build();
	}

	@POST
	@Path("/account/save")
	public Response updateAccount(Account obj){
		return Response.ok(Account.save(obj)).build();
	}
	
	@POST
	@Path("/account/delete")
	public Response deleteAccount(Account obj){
		return Response.ok(Account.delete(obj)).build();
	}
	
	
	@POST
	@Path("/booking/list")
	public Response getListBooking(String where){
		List<Booking> list = Booking.getListDynamic(where);
		GenericEntity<List<Booking>> res = new GenericEntity<List<Booking>>(list){};
		return Response.ok(res).build();
	}
	
	@POST
	@Path("/booking/first")
	public Response getFirstBooking(String where){
		Booking obj = Booking.getFirstDynamic(where);
		return Response.ok(obj).build();
	}

	@POST
	@Path("/booking/save")
	public Response updateBooking(Booking obj){
		return Response.ok(Booking.save(obj)).build();
	}
	
	@POST
	@Path("/booking/delete")
	public Response deleteBooking(Booking obj){
		return Response.ok(Booking.delete(obj)).build();
	}
	
	
	@POST
	@Path("/flight/list")
	public Response getListFlight(String where){
		List<Flight> list = Flight.getListDynamic(where);
		GenericEntity<List<Flight>> res = new GenericEntity<List<Flight>>(list){};
		return Response.ok(res).build();
	}
	
	@POST
	@Path("/flight/first")
	public Response getFirstFlight(String where){
		Flight obj = Flight.getFirstDynamic(where);
		return Response.ok(obj).build();
	}

/*	@POST
	@Path("/flight/save")
	public Response updateFlight(Flight obj){
		return Response.ok(Flight.save(obj)).build();
	}
	
	@POST
	@Path("/flight/delete")
	public Response deleteFlight(Flight obj){
		return Response.ok(Flight.delete(obj)).build();
	}*/
	
	@POST
	@Path("/aircraft/list")
	public Response getListAircraft(String where){
		List<Aircraft> list = Aircraft.getListDynamic(where);
		GenericEntity<List<Aircraft>> res = new GenericEntity<List<Aircraft>>(list){};
		return Response.ok(res).build();
	}
	
	@POST
	@Path("/aircraft/first")
	public Response getFirstAircraft(String where){
		Aircraft obj = Aircraft.getFirstDynamic(where);
		return Response.ok(obj).build();
	}

}
